<?php
  include '../../core/include/connect.php';
  include '../../core/include/ServiceAll.php';
  
/**
 * 
 */
class RoleManagement extends ServiceAll {
  protected $listRole = Array(
    "supperadmin" => "SUPPERADMIN",
    "admin"       => "ADMIN",
    "modder"      => "MODDER",
    "member"      => "MEMBER",
    "user"        => "USER"
  );
  
  protected function roleQuery($role){
    $role = parent::breakSqlInjection($role);
    $sql = "SELECT `MATAU` FROM `dvtb_quanly` WHERE `QUYENXEM`='$role'";
    mysql_query("SET NAMES utf8");
    $sqlResult = mysql_query($sql);
    return mysql_fetch_array($sqlResult);
  }
}

/**
 * 
 */
class ServiceManagement extends RoleManagement {
  private $listService = Array(
        "UserManagement",
        "ShipManagement",
        "Registration",
        "ScheduleManagement",
        "Map",
        "Tracking",
        "Navigation",
        "Weather",
        "HelpError"
  );
  protected $listView = Array("supperadmin","admin","modder","member","user");
  protected function getRole($viewer){
    return parent::roleQuery($viewer);
  }
  protected function supperadminService(){
    return $this->listService;
  }
  protected function adminService(){
    $service = array();
    for ($idx=1; $idx < count($this->listService); $idx++) { 
      array_push($service, $this->listService[$idx]);
    }
    return $service;
  }
  protected function modderService(){
    $service = array();
    for ($idx=3; $idx < count($this->listService); $idx++) { 
      array_push($service, $this->listService[$idx]);
    }
    return $service;
  }
  protected function memberService(){
    $service = array();
    for ($idx=4; $idx < count($this->listService)-1; $idx++) { 
      array_push($service, $this->listService[$idx]);
    }
    return $service;
  }
  protected function userService(){
    return array(
      $this->listService[4],
      $this->listService[count($this->listService)-1],
      $this->listService[count($this->listService)]
    );
  }
}

/**
 * 
 */
class RoleController extends ServiceManagement {
  private function getListService($listService){
    $listServiceName = array();
    for ($idx=0; $idx < count($listService); $idx++) {
      $serviceName = $listService[$idx]."Service";
      array_push($listServiceName, $serviceName);
    }
    return $listServiceName;
  }
  public function mappingRoleService($viewer){
    switch ($viewer) {
      case 'supperadmin':
        return $this->getListService($this->supperadminService());
        break;
      case 'admin':
        return $this->getListService($this->adminService());
        break;
      case 'modder':
        return $this->getListService($this->modderService());
        break;
      case 'member':
        return $this->getListService($this->memberService());
        break;
      case 'user':
        return $this->getListService($this->userService());
        break;
      default:
        return array("NOT-DEFINE-FUNCTION");
        break;
    }
  }
}
?>